<%-- 
    Document   : sendMessageToAgent
    Created on : Mar 2, 2013, 10:37:38 AM
    Author     : mudassar
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%@include file="../common/script.jsp" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <%@include file="../common/title.jsp" %>

        <script type="text/javaScript">
    
            function addOption(selectbox,text,value) {
                var optn = document.createElement("OPTION");
                optn.text = text;
                optn.value = value;
                selectbox.options.add(optn);
            }
    
            function moveRight(){
               
                var rightBox=document.form1.right_box;
                var leftBox=document.form1.left_box;
                var moved=0;
                for (var i=0; i<leftBox.length+moved; i++) {
                    if (leftBox.options[i-moved].selected == true) {
                        addOption(rightBox,leftBox.options[i-moved].text,leftBox.options[i-moved].value);
                        leftBox.remove(i-moved);
                        moved++;
                    }
                }
            }
            function moveLeft(){
              
                var rightBox=document.form1.right_box;
                var leftBox=document.form1.left_box;
                var moved=0;
                for (var i=0; i<rightBox.length+moved; i++) {
                    if (rightBox.options[i-moved].selected == true) {
                        addOption(leftBox,rightBox.options[i-moved].text,rightBox.options[i-moved].value);
                        rightBox.remove(i-moved);
                        moved++;
                    }
                }
            }
    
            function validateForm()
            {
                var rightBox=document.form1.right_box;
                var viewTiers="";
                document.form1.selectedCustomerIds.value="";
                for (var i=0; i<rightBox.length; i++) {
                    viewTiers += rightBox.options[i].value + ",";
                }
                viewTiers = viewTiers.substr(0, (viewTiers.length-1));
                document.form1.selectedCustomerIds.value=viewTiers;
                
                return true;
            }
        </script>
        <script type="text/javascript">
            var rules =new Array();
            rules[0]='right_box|required|please Select atleast one user';
            rules[1]='messageSubject|required|please Select Subject';
            rules[2]='messageBody|required|please Enter message';
        </script>
        
    </head>
    <body>
        <%@include file="../common/header.jsp" %>
        <%@include file="../common/menu.jsp" %>
        <div class="in_02">
            <%@include file="../common/message.jsp" %>
            <form:form id="form1" name="form1"  modelAttribute="message" cssClass="userInputForm" >
                <fieldset style="width: 40%;">
                    <legend><spring:message code="title.sendMesssage"/></legend>
                    <table class="formTable1">
                        <tr>
                            <td>Available Users :<br/><br/> 
                                <select name="left_box" id="left_box" multiple size="10" style="width: 100px;" ></select></td>
                            <td align="center" valign="center" class="script">
                                <br/><br/><br/>
                                <input type="button" value="<<" onClick="moveLeft();" name="leftButton" class="less_btn" />
                                <br/><br/><br/>
                                <input type="button" value=">>" onClick="moveRight();" name="rightButton" class="less_btn" /></td>
                            <td>Selected Users :<br/><br/>
                                <select name="right_box" id="right_box"  multiple size="10" style="width: 100px;"></select>
                                </td>
                        </tr>
                        
                        <tr>
                            <td colspan="3"><spring:message code="subject"/>:<br/>
                                <form:input path="messageSubject" cssClass="userInputLarge" />
                            <br/><span id="errorsDiv_messageSubject"></span></td>
                        </tr>
                        <tr>
                            <td colspan="3"><spring:message code="message"/>:<br/>
                                <form:textarea path="messageBody" cssClass="TextAreaForSms" />
                            <br/><span id="errorsDiv_messageBody"></span></td>
                        </tr>
                        
                        <tr>
                            <td align="left">
                                <input type="button" name="button" value="CANCEL" onclick="location.href='../home/index.htm'"  >
                            </td>

                            <td align="right">
                                <input type="submit"  name="button" value="SUBMIT" onclick=" validateForm();return yav.performCheck('form1', rules, 'inline'); "  />
                            </td>

                        </tr>
                    </table>
                            <input type="hidden" name="selectedCustomerIds" id="selectedCustomerIds"/>
                    <script laguage="javascript">
                        var rightBox=document.form1.right_box;
                        var leftBox=document.form1.left_box;
                        <c:forEach items="${userList}" var="parameter">
                            addOption(leftBox,'${parameter.username}','${parameter.userId}');
                        </c:forEach>
                        <c:forEach items="${selectedIllnessList}" var="parameter">
                            addOption(rightBox,'${parameter.username}','${parameter.userId}');
                        </c:forEach>
                    </script>
                </fieldset>
            </form:form>
    </body>
</html>
